#include"myQueque.h"
myDeque::myDeque(int capcity) {
	deque.resize(capcity);
	size = 0;
	rear = 0;
	front = 0;
}
bool myDeque::pushToFront(int val) {
	if (size < deque.size()) {
		if (size > 0)
		{
			front = (front == 0) ? deque.size() - 1 : front - 1;
			deque[front] = val;
		}
		else {
			deque[0]= val;
		}
		size++;
		return true;;
	}
	return false;
}
bool myDeque::popAtFront() {
	if (size > 0) {

		size--;
		front = (front == deque.size() - 1 )? 0 : front + 1;
		return true;
	}
	return false;
}
bool myDeque::pushToRear(int val) {
	if (size < deque.size()) {
		if (size == 0)
		{
			rear = (rear == size - 1) ? 0 : rear + 1;
			deque[rear] = val;
		}
		else {
			deque[0] = val;
		}
		size++;
		return true;;
	}
	return false;
}
bool myDeque::popAtRear() {
	if (size > 0) {
		size--;
		rear = (rear == 0) ? deque.size() - 1 : rear-1;
		return true;
	}
	return false;
}
int  myDeque::getFront() {
	if (size > 0) {
		return deque[front];
	}
	return -1;
}
int  myDeque::getRear() {
	if (size > 0) {
		return deque[rear];
	}
	return -1;
}